package com.shujia.interfacer;

import com.shujia.reflect.DataRead;
import com.shujia.reflect.Score;
import com.shujia.reflect.Student;

import java.util.ArrayList;

public class Demo5Join {
    public static void main(String[] args) {
        ArrayList<Score> scores = DataRead.read("java/data/score.txt", Score.class);

        DataSet<Score> scoDS = new DataSet<>(scores);

        ArrayList<Student> students = DataRead.read("java/data/students.txt", Student.class);


        DataSet<Student> stuDS = new DataSet<>(students);


        scoDS.join(stuDS, new KeySelect<Score, String>() {
            @Override
            public String select(Score score) {
                return score.getSid();
            }
        }, new KeySelect<Student, String>() {
            @Override
            public String select(Student student) {
                return student.getId();
            }
        }, new ProcessFunaction<Score, Student, String>() {
            @Override
            public String process(Score score, Student student) {
                return student.toString() + "\t" + score.toString();
            }
        }).print();


    }
}
